﻿'Params
'limit (Optional) : Limit the number of similar artists returned
'artist (Required (unless mbid)] : The artist name
'autocorrect[0|1] (Optional) : Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response.
'mbid (Optional) : The musicbrainz id for the artist
'api_key (Required) : A Last.fm API key.

'Auth
' This service does not require authentication. 

Public Structure ArtistGetSimilarResponse
	Dim artists() As Artist
End Structure

Public Class ArtistGetSimilar
	Inherits BaseRequest
	Dim artist As String = ""
	Dim mbid As String = ""
	Dim autocorrect As String = ""
	Dim limit As String = ""

	Public xmlresponse As XDocument = Nothing

	Public Sub New(artist As String, mbid As String, autocorrect As String, limit As String)
		Me.artist = artist
		Me.mbid = mbid
		Me.autocorrect = autocorrect
		Me.limit = limit
	End Sub

	Public Sub sendRequest()
		ClearMembers()

		AddMember("method", "artist.getSimilar")
		AddMember("artist", artist, String.IsNullOrEmpty(mbid))
		AddMember("mbid", mbid, False)
		AddMember("autocorrect", autocorrect, False)
		AddMember("limit", limit, False)
		AddMember("api_key", My.Settings.api_key, False)

		xmlresponse = sendGETResponse(True)
	End Sub

	Public Function getResponse() As ArtistGetSimilarResponse
		Dim response As ArtistGetSimilarResponse = Nothing

		Try
			Dim count = xmlresponse.<artists>.<artist>.Count()
			If (count > 0) Then
				ReDim response.artists(count - 1)
				For i As Integer = 0 To count - 1
					response.artists(i) = New Artist(xmlresponse.<artists>.<artist>(i))
				Next
			End If
		Catch ex As Exception

		End Try
		Return response
	End Function

End Class
